from nekonekotrace.models import *
import datetime

def addCatImpression(catid, userid, content):
	catid = CatInfo.objects.get(id=catid)
	userid = OpenUser.objects.get(id=userid)
	cimp = CatImpression(CatID=catid, UserID=userid, Content=content, Time=datetime.datetime.now())
	cimp.save()
	
def dpNewImpression(userid, catid, content):
	catinfo = CatInfo.objects.get(id=catid)
	user = OpenUser.objects.get(id=userid)
	catimp = CatImpression(CatID=catinfo, UserID=user, Content=content, Time=datetime.datetime.now())
	catimp.save()
	cs = CatStatus(CatID=catinfo, Type=4, TargetID=catimp.id)
	cs.save()
	
def dpNewLocationInfo(locationid, catid):
	catid = CatInfo.objects.get(id=catid)
	locationid = Location.objects.get(id=locationid)
	linfo = LocationInfo(CatID=catid, Time=datetime.datetime.now(), LocationID=locationid)
	linfo.save()
	cs = CatStatus(CatID=catid, Type=0, TargetID=linfo.id)
	cs.save()
	

def dpNewTreat(userid, catid):
	userid = OpenUser.objects.get(id=userid)
	catid = CatInfo.objects.get(id=catid)
	tt = Treat(CatID=catid, Time=datetime.datetime.now(), Author=userid)
	tt.save()
	cs = CatStatus(CatID=catid, Type=1, TargetID=tt.id)
	cs.save()
	say = Saying(Time=tt.Time, CatID=catid, Content=userid.Name + ', thank you for your treat!')
	say.save()
	cs = CatStatus(CatID=catid, Type=3, TargetID=say.id)
	cs.save()
	
def dpNewAlbum(fname, catid, userid):
	userid = OpenUser.objects.get(id=userid)
	catid = CatInfo.objects.get(id=catid)
	tt = Album(CatID=catid, URL=fname, Time=datetime.datetime.now(), Author=userid)
	tt.save()
	cs = CatStatus(CatID=catid, Type=2, TargetID=tt.id)
	cs.save()
